package DataBase;

import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import com.mchange.v2.c3p0.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author Daniel Cervantes Avila
 */

public class AdminConexion { 			
	private String configuracion;
        private DBConfiguration config;
        private ComboPooledDataSource pool;

        public AdminConexion(){
            try {
                config = new DBConfiguration();
                pool = new ComboPooledDataSource();
                pool.setDriverClass(config.obtenerControlador());
                pool.setJdbcUrl(config.obtenerFlujo()+"/"+config.obtenerNombreBD());
                pool.setUser(config.obtenerUsuario());
                pool.setPassword(config.obtenerContrasena());
                pool.setMaxStatements(200);                
                pool.setInitialPoolSize(1);
                pool.setMinPoolSize(1);
                pool.setMaxPoolSize(200);
                
            } catch (PropertyVetoException ex) {
                //Logger.getLogger(AdminConexion.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
       
    	
        public String getDBConfig(){
                return this.configuracion;
        }

        public Connection obtenerConnection() throws SQLException{
            return pool.getConnection();
            
        }
            

        public void liberarConnextion(Connection connection){
            
            try {
                connection.close();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }finally{
                connection=null;
            }
        }

    /*
    public PreparedStatement obtenerPreparedStatement(String sql) throws SQLException{
        return this.connection.prepareStatement(sql);
    }*/
    
    /* public Statement crearStatement(){
        Statement stmt=null;
        try {
            stmt=obtenerConnection().createStatement();
        } catch (SQLException ex) {
            Logger.getLogger(ConManager.class.getName()).log(Level.SEVERE, null, ex);
        }
        return stmt;
    }

    public PreparedStatement obtenerPrepareStatement(String sql){
        try {
            return obtenerConnection().prepareStatement(sql);
        } catch (SQLException ex) {
            Logger.getLogger(ConManager.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }

    }*/
}
 
